package task.gui;

import java.util.Set;

import task.dao.ObjectDb;

public class DbUtil {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ObjectDb db = new ObjectDb("data/TaskCrab.db");
		boolean changed = false;
		for (String arg : args) {
			try {
				System.out.printf("Removing %s%n", arg);
				Object o = db.remove(arg);
				if (o == null) {
					System.out.printf(" (didn't find %s)%n", arg);
				} else {
					changed = true;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		Set<String> keys = db.keySet();
		System.out.printf("Keys can be removed by giving them as comand line%nCurrent keys:%n");
		for (String key : keys) {
			try {
				System.out.printf("  %s%n", key);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		if (changed) {
			try {
				db.save();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
